home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / performancing_api.js < prev    next >
Encoding:
JavaScript  |  2007-07-24  |  55.6 KB  |  1,430 lines

  1. // Some of the API Functions below are derived from GPL code originally by Flock Inc:
  2. // Released under the same GLP license.
  3. //
  4. // For the original source, see: http://cvs-mirror.flock.com/index.cgi/mozilla/browser/components/flock/blog/content/blogapi.js?rev=1.19&content-type=text/vnd.viewcvs-markup
  5. // and http://cvs-mirror.flock.com/index.cgi/mozilla/browser/components/flock/blog/content/
  6. //
  7. // Usage: myblog.init('blogger', '0123456789ABCDEF', 'http://plant.blogger.com/api/RPC2' ,'3724458', null, 'BillyBob',  'bbBaby'  )
  8.  
  9.  
  10. var gPFFDebugTemp = [];
  11.  
  12. var perFormancingBlogAPI= function () {
  13.     this.addCategories = false;
  14.     this.extendedEntries = false;
  15.     
  16.     this.supportsPages = false;
  17. }
  18.  
  19. perFormancingBlogAPI.prototype = {
  20.     init: function (aName, aAppKey, aAPILink, aBlogID, aPreferred, aUsername, aPassword, aNeedsAuth) {
  21.         this.name = aName;
  22.         this.appKey = aAppKey;
  23.         this.editLink = "";
  24.         this.apiLink = aAPILink;
  25.         this.appKey = "";
  26.         this.blogID = aBlogID;
  27.         this.username = aUsername;
  28.         this.password = aPassword;
  29.         this.needsAuth = aNeedsAuth;
  30.     },
  31.     setAuth: function (aUsername, aPassword, aURL){},
  32.     doSetup: function (){},
  33.     doAuth: function (aUsername, aPassword) {},
  34.     newPost: function (aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {},
  35.     editPost: function (aPostid, aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {},
  36.     deletePost: function (aPostid, aEditURI) {},
  37.     deletePage: function (pageId) {},
  38.     getUsersBlogs: function () {},
  39.     getRecentPosts: function (aNumber) {},
  40.     setPostCategories: function (aPostid, aCategories) {},
  41.     getCategoryList: function () {},
  42.     publishPost: function (aPostid) {},
  43.     fileUpload: function (aFileName, aMimeType, aDataString) {}
  44.     //newMediaObject: function (aFileName, aMimeType, aB64DataStr) {}
  45. }
  46.  
  47. //This Function is derived from GPL code originally by Flock Inc:
  48. //myblog = new perFormancingBloggerAPI()
  49. var perFormancingBloggerAPI = function () {
  50.     this.newPost = function (aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  51.         var argArray = [this.apiLink, this.appKey, this.blogID, this.username, this.password, aDescription, aPublish];
  52.         return performancingAPICalls.blogger_newPost(argArray);
  53.     };
  54.     this.editPost = function (aPostid, aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) { 
  55.         var argArray = [this.apiLink, this.appKey, aPostid, this.username, this.password, aDescription, aPublish];
  56.         return performancingAPICalls.blogger_editPost(argArray);
  57.     };
  58.     this.deletePost = function (aPostid) {
  59.         var argArray = [this.apiLink, this.appKey, aPostid, this.username, this.password, true];
  60.         return performancingAPICalls.blogger_deletePost(argArray);
  61.     };
  62.     this.deletePage = function (pageId) {
  63.         return false;
  64.     };
  65.     this.getUsersBlogs = function () {
  66.         var argArray = [this.apiLink, this.appKey, this.username, this.password];
  67.         return performancingAPICalls.blogger_getUsersBlogs(argArray);
  68.     };
  69.     this.getRecentPosts = function (aNumber) {
  70.         var argArray = [this.apiLink, this.appKey, this.blogID, this.username, this.password, aNumber];
  71.         return performancingAPICalls.blogger_getRecentPosts(argArray);
  72.     };
  73.     this.getCategoryList = function (argArray) { //Not available
  74.         return false;
  75.     };
  76.     this.setPostCategories = function (aPostid, aCategories) { //Not Available
  77.         return false;
  78.     };
  79.     this.publishPost = function (aPostid) {
  80.         return false;
  81.     };
  82. }
  83. perFormancingBloggerAPI.prototype = new perFormancingBlogAPI();
  84.  
  85. //This Function is derived from GPL code originally by Flock Inc:
  86. var performancingMetaweblogAPI = function () {
  87.     this.newPost = function (aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  88.         var content_t =
  89.         {
  90.             title: aTitle,
  91.             description: aDescription,
  92.             categories: aArrayOfCats
  93.         };
  94.         //var argArray = [];
  95.         var argArray = [this.apiLink, this.blogID, this.username, this.password, content_t, aPublish];
  96.         return performancingAPICalls.metaWeblog_newPost(argArray);
  97.     };
  98.     this.editPost = function (aPostid, aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  99.         var ourNewDate = "";
  100.         if(aDateCreated != ""){
  101.            ourNewDate = new Date(aDateCreated)
  102.         }
  103.         var content_t =
  104.         {
  105.             title: aTitle,
  106.             description: aDescription,
  107.             dateCreated: ourNewDate,
  108.             categories: aArrayOfCats
  109.             //dateCreated: "",
  110.         };
  111.         var argArray = [this.apiLink, aPostid, this.username, this.password, content_t, aPublish];
  112.         return performancingAPICalls.metaWeblog_editPost(argArray);
  113.     };
  114.     this.deletePost = function (aPostid) {
  115.         var argArray = [this.apiLink, this.appKey, aPostid, this.username, this.password, true];
  116.         return performancingAPICalls.blogger_deletePost(argArray);
  117.     };
  118.     this.deletePage = function (pageId){
  119.         return false;
  120.     };
  121.     this.getUsersBlogs = function () {
  122.         var argArray = [this.apiLink, this.appKey, this.username, this.password];
  123.         return performancingAPICalls.blogger_getUsersBlogs(argArray);
  124.     };
  125.     this.getRecentPosts = function (aNumber) {
  126.         var argArray = [this.apiLink, this.blogID, this.username, this.password, aNumber];
  127.         return performancingAPICalls.metaWeblog_getRecentPosts(argArray);
  128.         //return blogger_getRecentPosts(this.apiLink, this.appKey, this.blogID, this.username, this.password, aNumber);
  129.     };
  130.     /*
  131.     metaWeblog.getCategories 
  132.     metaWeblog.getCategories (blogid, username, password) returns struct
  133.     The struct returned contains one struct for each category, containing the following elements: description, htmlUrl and rssUrl.
  134.     This entry-point allows editing tools to offer category-routing as a feature.
  135.     */
  136.     this.getCategoryList = function () { //Not Available
  137.         //return false;
  138.         var argArray = [this.apiLink, this.blogID, this.username, this.password];
  139.         return performancingAPICalls.metaWeblog_getCategoryList(argArray);
  140.         
  141.     };
  142.     this.setPostCategories = function (aPostid, aCategories) { //Not Available
  143.         //var argArray = [];
  144.         return false;
  145.     };
  146.     this.publishPost = function (aPostid) {
  147.         return false;
  148.     };
  149.     
  150.     //metaWeblog.newMediaObject (blogid, username, password, struct)
  151.     this.fileUpload = function (aFileName, aMimeType, aDataString) {
  152.         var content_t =
  153.         {
  154.             name: aFileName,
  155.             type: aMimeType,
  156.             bits: aDataString.toString() //aBase64Data
  157.         };
  158.         var argArray = [this.apiLink, this.blogID, this.username, this.password, content_t];
  159.         return performancingAPICalls.metaWeblog_newMediaObject(argArray);
  160.     };
  161. }
  162. performancingMetaweblogAPI.prototype = new perFormancingBlogAPI();
  163.  
  164. var perFormancingMovableTypeAPI = function () {
  165.     this.newPost = function (aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  166.         var content_t = {
  167.             title : aTitle,
  168.             description : aDescription,
  169.             categories : aArrayOfCats
  170.         };
  171.  
  172.         var argArray = [this.apiLink, this.blogID, this.username, this.password, content_t, aPublish];
  173.         return performancingAPICalls.metaWeblog_newPost(argArray);
  174.     };
  175.     
  176.     this.newPage = function (aTitle, aDescription, aDateCreated, aPublish) {
  177.         var content_t = {
  178.             title : aTitle,
  179.             description : aDescription
  180.         };
  181.  
  182.         var argArray = [this.apiLink, this.blogID, this.username, this.password, content_t, aPublish];
  183.         return performancingAPICalls.wp_newPage(argArray);
  184.     };
  185.     
  186.     this.editPost = function (aPostid, aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  187.         var ourNewDate = "";
  188.         
  189.         if(aDateCreated != ""){
  190.             ourNewDate = new Date(aDateCreated)
  191.         }
  192.  
  193.         var content_t = {
  194.             title: aTitle,
  195.             description: aDescription,
  196.             categories: aArrayOfCats,
  197.             dateCreated: ourNewDate
  198.         };
  199.         
  200.         var argArray = [this.apiLink, aPostid, this.username, this.password, content_t, aPublish];
  201.         return performancingAPICalls.metaWeblog_editPost(argArray);
  202.     };
  203.     
  204.     this.deletePost = function (aPostid) {
  205.         var argArray = [this.apiLink, this.appKey, aPostid, this.username, this.password, true];
  206.         return performancingAPICalls.blogger_deletePost(argArray);
  207.     };
  208.     
  209.     this.deletePage = function (pageId) {
  210.         var argArray = [this.apiLink, this.blogID, this.username, this.password, pageId, true];
  211.         return performancingAPICalls.wp_deletePage(argArray);
  212.     };
  213.     
  214.     this.getUsersBlogs = function () {
  215.         var argArray = [this.apiLink, this.appKey, this.username, this.password];
  216.         return performancingAPICalls.blogger_getUsersBlogs(argArray);
  217.     };
  218.     
  219.     this.getRecentPosts = function (aNumber) {
  220.         var argArray = [this.apiLink, this.blogID, this.username, this.password, aNumber];
  221.         return performancingAPICalls.metaWeblog_getRecentPosts(argArray);
  222.     };
  223.     
  224.     this.getPages = function () {
  225.         var argArray = [this.apiLink, this.blogID, this.username, this.password];
  226.         return performancingAPICalls.wp_getPages(argArray);
  227.     };
  228.     
  229.     this.getPageList = function () {
  230.         var argArray = [this.apiLink, this.blogID, this.username, this.password];
  231.         return performancingAPICalls.wp_getPageList(argArray);
  232.     };
  233.     
  234.     this.getCategoryList = function () {
  235.         var argArray = [this.apiLink, this.blogID, this.username, this.password];
  236.         return performancingAPICalls.mt_getCategoryList(argArray);
  237.     };
  238.     
  239.     this.newCategory = function (aCategory) {
  240.         var argArray = [this.apiLink, this.blogID, this.username, this.password, { name : aCategory} ];
  241.         return performancingAPICalls.wp_newCategory(argArray);
  242.     };
  243.     
  244.     this.setPostCategories = function (aPostid, aCategories) {
  245.         var argArray = [this.apiLink, aPostid, this.username, this.password, aCategories];
  246.         return performancingAPICalls.mt_setPostCategories(argArray);
  247.     };
  248.  
  249.     this.publishPost = function (aPostid) {
  250.         var argArray = [this.apiLink, aPostid, this.username, this.password];
  251.         return performancingAPICalls.mt_publishPost(argArray);
  252.     };
  253.  
  254.     this.fileUpload = function (aFileName, aMimeType, aDataString) {
  255.         var content_t = {
  256.             name: aFileName,
  257.             type: aMimeType,
  258.             bits: aDataString.toString()
  259.         };
  260.         
  261.         var argArray = [this.apiLink, this.blogID, this.username, this.password, content_t];
  262.         return performancingAPICalls.metaWeblog_newMediaObject(argArray);
  263.     };
  264.     
  265.     this.supportsPages = true;
  266. };
  267.  
  268. perFormancingMovableTypeAPI.prototype = new perFormancingBlogAPI();
  269.  
  270. var perFormancingAtomAPI = function () {
  271.     this.newPost = function (aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  272.         var J = new perFormancingAtomAPIObject();
  273.         J.init2(this.apiLink, this.username, this.password);
  274.         J.newPost(aTitle, aDescription, aDateCreated, aPublish);
  275.     };
  276.     this.editPost = function (aPostid, aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish, aEditURI, aAtomID) {
  277.         var J = new perFormancingAtomAPIObject();
  278.         J.init2(this.apiLink, this.username, this.password);
  279.         J.editPost(aPostid, aTitle, aDescription, aDateCreated, aPublish, aEditURI, aAtomID);
  280.     };
  281.     this.deletePost = function (aPostid, aEditURI) {
  282.         var J = new perFormancingAtomAPIObject();
  283.         J.init2(this.apiLink, this.username, this.password);
  284.         J.deletePost(aPostid, aEditURI);
  285.     };
  286.     this.getUsersBlogs = function () {
  287.         var J = new perFormancingAtomAPIObject();
  288.         J.init2(this.apiLink, this.username, this.password);
  289.         J.getUsersBlogs();
  290.     };
  291.     this.getRecentPosts = function (aNumber) {
  292.         var J = new perFormancingAtomAPIObject();
  293.         J.init2(this.apiLink, this.username, this.password);
  294.         J.getRecentPosts();
  295.     };
  296.     this.getCategoryList = function () {
  297.         //aListener.onResult(null);
  298.         return false;
  299.     };
  300.     this.setPostCategories = function (aPostid, aCategories) {
  301.         //aListener.onResult(null);
  302.         return false;
  303.     };
  304.     
  305.     this.publishPost = function (aPostid) {
  306.          return false;
  307.     };
  308.     
  309.     this.deletePage = function () {
  310.         return false;
  311.     };
  312. }
  313. perFormancingAtomAPI.prototype = new perFormancingBlogAPI();
  314.  
  315. //BLOGGER BETA
  316. var perFormancingBloggerAtomAPI = function () {
  317.     this.theObject = new perFormancingBloggerAtomAPIObject();
  318.     this.theObject.authToken = null;
  319.     this.theObject.isLoggedIn = null;
  320.     
  321.     this.newPost = function (aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish) {
  322.         //var J = new perFormancingBloggerAtomAPIObject();
  323.         this.theObject.init2(this.apiLink, this.username, this.password);
  324.         this.theObject.newPost(aTitle, aDescription, aDateCreated, aPublish);
  325.     };
  326.     this.editPost = function (aPostid, aTitle, aDescription, aArrayOfCats, aDateCreated, aPublish, aEditURI, aAtomID) {
  327.         //var J = new perFormancingBloggerAtomAPIObject();
  328.         this.theObject.init2(this.apiLink, this.username, this.password);
  329.         this.theObject.editPost(aPostid, aTitle, aDescription, aDateCreated, aPublish, aEditURI, aAtomID);
  330.     };
  331.     this.deletePost = function (aPostid, aEditURI) {
  332.         //var J = new perFormancingBloggerAtomAPIObject();
  333.         this.theObject.init2(this.apiLink, this.username, this.password);
  334.         this.theObject.deletePost(aPostid, aEditURI);
  335.     };
  336.     this.getUsersBlogs = function () {
  337.         //var J = new perFormancingBloggerAtomAPIObject();
  338.         this.theObject.init2(this.apiLink, this.username, this.password);
  339.         this.theObject.getUsersBlogs();
  340.     };
  341.     this.getRecentPosts = function (aNumber) {
  342.         //var J = new perFormancingBloggerAtomAPIObject();
  343.         this.theObject.init2(this.apiLink, this.username, this.password);
  344.         this.theObject.getRecentPosts();
  345.     };
  346.     this.getCategoryList = function () {
  347.         //aListener.onResult(null);
  348.         return false;
  349.     };
  350.     this.setPostCategories = function (aPostid, aCategories) {
  351.         //aListener.onResult(null);
  352.         return false;
  353.     };
  354.     this.publishPost = function (aPostid) {
  355.          return false;
  356.     };
  357.     this.doAuth = function () {
  358.         //var J = new perFormancingBloggerAtomAPIObject();
  359.         this.theObject.init2(this.apiLink, this.username, this.password);
  360.         this.theObject.doAuth();
  361.     };
  362.     this.doSetup = function () {
  363.         //var J = new perFormancingBloggerAtomAPIObject();
  364.         //this.theObject.init2(this.apiLink, this.username, this.password);
  365.         this.theObject.doSetup();
  366.     };
  367.     
  368.     this.deletePage = function () {
  369.         return false;
  370.     };
  371.     
  372.     this.addCategories = true;
  373. }
  374. perFormancingBloggerAtomAPI.prototype = new perFormancingBlogAPI();
  375.  
  376.  
  377. var performancingAPICalls = new Object();
  378.  
  379. performancingAPICalls = {
  380.     //myParams  = [url, appkey, blogid, username, password, content, publish]
  381.     blogger_newPost: function(myParams) {
  382.       return bfXMLRPC.makeXML("blogger.newPost", myParams);
  383.     },
  384.     
  385.     //myParams  = [url, appkey, postid, username, password, content, publish]
  386.     blogger_editPost: function(myParams) {
  387.       return bfXMLRPC.makeXML("blogger.editPost", myParams);
  388.     },
  389.     
  390.     //myParams  = [url, appkey, postid, username, password, publish]
  391.     blogger_deletePost: function(myParams) {
  392.         //alert(appkey + " " + postid + " " + username + " " + password + " " + publish + " ");
  393.       return bfXMLRPC.makeXML("blogger.deletePost", myParams);
  394.     },
  395.     
  396.     //myParams  = [url, appkey, blogid, username, password, numberOfPosts]
  397.     blogger_getRecentPosts: function(myParams) {
  398.       return bfXMLRPC.makeXML("blogger.getRecentPosts", myParams);
  399.     },
  400.     
  401.     //myParams  = [url, appkey, username, password]
  402.     blogger_getUsersBlogs: function(myParams) {
  403.       return bfXMLRPC.makeXML("blogger.getUsersBlogs", myParams);
  404.     },
  405.     
  406.     //myParams  = [url, appkey, username, password]
  407.     blogger_getUserInfo: function(myParams) {
  408.       return bfXMLRPC.makeXML("blogger.getUserInfo", myParams);
  409.     },
  410.     
  411.     //myParams  = [url, blogid, username, password, content_t, publish]
  412.     metaWeblog_newPost: function(myParams) {
  413.       return bfXMLRPC.makeXML("metaWeblog.newPost", myParams);
  414.     },
  415.     
  416.     metaWeblog_editPost: function(myParams) {
  417.       return bfXMLRPC.makeXML("metaWeblog.editPost", myParams);
  418.     },
  419.     
  420.     //myParams  = [url, blogid, username, password, numberOfPosts]
  421.     metaWeblog_getRecentPosts: function(myParams) {
  422.       return bfXMLRPC.makeXML("metaWeblog.getRecentPosts", myParams);
  423.     },
  424.     
  425.     //myParams  = [url, blogid, username, password]
  426.     metaWeblog_getCategoryList: function(myParams) {
  427.       return bfXMLRPC.makeXML("metaWeblog.getCategories", myParams);
  428.     },
  429.     
  430.     //myParams  = [url, blogid, username, password, mediaStruct]
  431.     metaWeblog_newMediaObject: function(myParams) {
  432.       return bfXMLRPC.makeXML("metaWeblog.newMediaObject", myParams);
  433.     },
  434.     
  435.     //myParams  = [url, blogid, username, password, numberOfPosts]
  436.     mt_getRecentPostTitles: function(myParams) {
  437.       return bfXMLRPC.makeXML("mt.getRecentPostTitles", myParams);
  438.     },
  439.     
  440.     //myParams  = [url, blogid, username, password]
  441.     mt_getCategoryList: function(myParams) {
  442.       return bfXMLRPC.makeXML("mt.getCategoryList", myParams);
  443.     },
  444.     
  445.     //myParams  = [url, postid, username, password, categories]
  446.     mt_setPostCategories: function(myParams) {
  447.       return bfXMLRPC.makeXML("mt.setPostCategories", myParams);
  448.     },
  449.     //mt_publishPost
  450.     //myParams  = [url, postid, username, password]
  451.     mt_publishPost: function(myParams) {
  452.       return bfXMLRPC.makeXML("mt.publishPost", myParams);
  453.     },
  454.     
  455.     wp_getPage : function (myParams) {
  456.         return bfXMLRPC.makeXML("wp.getPage", myParams);
  457.     },
  458.     wp_getPages : function (myParams) {
  459.         //        $blog_id    = $args[0];
  460.         //      $username    = $args[1];
  461.         //      $password    = $args[2];
  462.         return bfXMLRPC.makeXML("wp.getPages", myParams);
  463.     },
  464.     wp_newPage : function (myParams) {
  465.         return bfXMLRPC.makeXML("wp.newPage", myParams);
  466.     },
  467.     wp_deletePage : function (myParams) {
  468.         return bfXMLRPC.makeXML("wp.deletePage", myParams);
  469.     },
  470.     wp_editPage : function (myParams) {
  471.         return bfXMLRPC.makeXML("wp.editPage", myParams);
  472.     },
  473.     wp_getPageList : function (myParams) {
  474.         return bfXMLRPC.makeXML("wp.getPageList", myParams);
  475.     },
  476.     wp_getAuthors : function (myParams) {
  477.         return bfXMLRPC.makeXML("wp.getAuthors", myParams);
  478.     },
  479.     wp_newCategory : function (myParams) {
  480.         return bfXMLRPC.makeXML("wp.newCategory", myParams);
  481.     },
  482.     wp_suggestCategories : function (myParams) {
  483.         return bfXMLRPC.makeXML("wp.suggestCategories", myParams);
  484.     }
  485. }
  486.  
  487. function perFormancingAtomAPIObject() {
  488. }
  489.  
  490. perFormancingAtomAPIObject.prototype = {
  491.     _req: null,
  492.     _url: null,
  493.  
  494.     ERROR_HTTP:   10,
  495.     ERROR_FAULT:   11,
  496.     ERROR_PARSER:   12,
  497.  
  498.     init2: function(aUrl, aUsername, aPassword) {
  499.         this._url = aUrl;
  500.         this._user = aUsername;
  501.         this._pass = aPassword;
  502.     },
  503.  
  504.     doRequest: function( method, url, body, processor) {
  505.         var fault =  {
  506.                     faultString: "Due to Blogger.com's recent API changes, you will need to re-add this Blogger account to PFF\n(Click the 'Add' Button to re-add your account)\nIf you have problems, please visit the Performancing.com support forums for assistance.\nhttp://performancing.com/forum/firefox"
  507.                 };
  508.                 alert(fault.faultString);
  509.     },
  510.  
  511.     getRecentPosts: function() {
  512.         //var url = this._url; 
  513.         //url.match(/(.+\/)(.+)/);
  514.         //if(RegExp.$2=="post") {
  515.         //    url = RegExp.$1 + "feed";
  516.         //}
  517.         this.doRequest("GET", this._url,null, this.parseRecentPosts);
  518.         return true;
  519.     },
  520.     getUsersBlogs: function() {
  521.         //var url = this._url.match(/(.+)\//);
  522.         //url = RegExp.$1;
  523.         //this.doRequest("GET", url, null, this.parseUsersBlogs);
  524.         this.doRequest("GET", this._url, null, this.parseUsersBlogs);
  525.     },
  526.  
  527.     parseUsersBlogs: function( inst) {
  528.         //dump("\n\n parseUsersBlogs ATOM \n\n");
  529.         try {
  530.             var rval = new Array();
  531.             var dom = inst._req.responseXML;
  532.             var links = dom.getElementsByTagName("link");
  533.             for(var i=0;i<links.length;++i)
  534.             {
  535.                 var link = links[i];
  536.                 var title = link.getAttribute("title");
  537.                 var rel = link.getAttribute("rel");
  538.                 var href = link.getAttribute("href");
  539.                 if(rel!="service.post") continue;
  540.  
  541.                 href.match(/.+\/(.+)/);
  542.                 var bid = RegExp.$1;
  543.  
  544.                 var obj  =
  545.                 {
  546.                     blogName: title,
  547.                     blogid:  bid,
  548.                     url:  href
  549.                 };
  550.                 rval[rval.length++] = obj;
  551.             }
  552.             //listener.onResult(rval);
  553.             performancing_xmlcall.processData(rval, null, 'accountwizard', "", true);
  554.         }
  555.         catch(e) {
  556.             //alert(e + " " + e.lineNumber);
  557.             //dump("\n\n Error ParsingBlogs: " + e + "\n\n");
  558.         }
  559.     },
  560.  
  561.     parseRecentPosts: function( inst) {
  562.         //dump("\n\n parseRecentPosts ATOM \n\n");
  563.         var rval = new Array();
  564.         var dom = inst._req.responseXML;
  565.         var entries = dom.getElementsByTagName("entry");
  566.         for(var i=0;i<entries.length;++i)
  567.         {
  568.             try
  569.             {
  570.                 var entry_n = entries[i];
  571.                 var content_n = inst.getNamedChild(entry_n, "content");
  572.                 var title_n = inst.getNamedChild(entry_n, "title");
  573.                 var created_n = inst.getNamedChild(entry_n, "issued");
  574.                 var author_n = inst.getNamedChild(entry_n, "author");
  575.                 var link_n = null;
  576.                 var atomid_n = inst.getNamedChild(entry_n, "id");
  577.                 var atomid = "";
  578.                 if(atomid_n) atomid = atomid_n.firstChild.nodeValue;
  579.  
  580.                 for(var j=0;j<entry_n.childNodes.length;++j) {
  581.                     if(entry_n.childNodes[j].nodeName=="link") {
  582.                         var tmp = entry_n.childNodes[j];
  583.                         if(tmp.getAttribute("rel").match(/edit/)) {
  584.                             link_n = tmp;
  585.                         }
  586.                     }
  587.                 }
  588.  
  589.                 var href = link_n.getAttribute("href");
  590.                 href.match(/.+\/(.+)/);
  591.                 var postid = RegExp.$1;
  592.  
  593.                 var dateval = created_n.firstChild.nodeValue;
  594.                 //var date = flock_parseDate(dateval);
  595.                 var val = dateval;
  596.                 var dateutc =  Date.UTC(val.slice(0, 4), val.slice(4, 6) - 1, 
  597.                         val.slice(6, 8), val.slice(9, 11), val.slice(12, 14), 
  598.                         val.slice(15));
  599.                 var date =  new Date(dateutc);
  600.  
  601.                 var xs = new XMLSerializer();
  602.  
  603.                 var data = "";
  604.                 if(content_n) {
  605.                     for(var j=0;j<content_n.childNodes.length;++j) {
  606.                         data += xs.serializeToString(content_n.childNodes.item(j));
  607.                     }
  608.                 }
  609.                 data = data.replace(/</g,"<");
  610.                 data = data.replace(/>/g,">");
  611.                 data = data.replace(/"/g,"\"");
  612.                 data = data.replace(/&/g,"&");
  613.  
  614.                 var obj  =
  615.                 {
  616.                     description: data,
  617.                     title: title_n.firstChild.nodeValue,
  618.                     dateCreated: date,
  619.                     postid:  postid,
  620.                     editURI:  href,
  621.                     atomid:  atomid
  622.                 };
  623.                 rval[rval.length] = obj;
  624.             }
  625.             catch(e)
  626.             {
  627.                 //alert(e);
  628.                 //dump("\n\n parseRecentPosts ATOM ERROR:" + e + "\n\n");
  629.             }
  630.         }
  631.         //listener.onResult(rval);
  632.         //dump("\n\n parseRecentPosts ATOM Finished \n\n");
  633.         //gLastPostID = postid;
  634.         performancing_xmlcall.processData(rval, null, 'historycall', "", true);
  635.     },
  636.     getNamedChild: function(node, name) {
  637.         for(var i=0;i<node.childNodes.length;++i) {
  638.             if(node.childNodes[i].nodeName==name) return node.childNodes[i];
  639.         }
  640.         return null;
  641.     },
  642.     deletePost: function ( postid, aEditURI) {
  643.         var url = this._url;
  644.         if(postid) url += "/" + postid;
  645.         if(aEditURI) url = aEditURI;
  646.         this.doRequest("DELETE", url,null, this.handleDelete);
  647.     },
  648.     doPost: function ( method, postid, title, description, date_created, doPublish, aEditURI, aAtomID, isEdit) {
  649.  
  650.         var url = this._url;
  651.         if(postid) url += "/" + postid;
  652.  
  653.         //if(aEditURI) url += "/" + aEditURI;
  654.  
  655.         //var date = bfXMLRPC.iso8601Format(date_created);
  656.         var date = "";
  657.         try{
  658.             date = bfXMLRPC.iso8601Format(date_created);
  659.         }catch(e){
  660.             //foo
  661.         }
  662.  
  663.         var body = "";
  664.         var version = "ScribeFire 1.4.2";
  665.         var theBlogCharType = gPerformancingUtil.getCharType();
  666.         body += '<?xml version="1.0" encoding="UTF-8" ?>';
  667.         body += '<entry xmlns="http://purl.org/atom/ns#">';
  668.  
  669.         var draft = "false";
  670.         if(doPublish == false || doPublish == 'bool0') draft = "true";
  671.         //alert("Is Draft? " + draft + " doPublish: " + doPublish);
  672.         
  673.         var useEntities = true;
  674.         try{
  675.             useEntities = gPerformancingUtil.prefs.getBoolPref('publish.usehtmlentities')
  676.         }catch(e){
  677.             useEntities = false;
  678.         }
  679.         //Use HTML Entities, thanks Theo
  680.         if(useEntities){
  681.             var entity_description = "";
  682.             for (var desc_i=0; desc_i < description.length; desc_i++){
  683.                 entity_description += "&#" + description.charCodeAt(desc_i) + ";";
  684.             }
  685.         
  686.             var entity_title = "";
  687.             for (var title_i=0; title_i < title.length; title_i++){
  688.                 entity_title += "&#" + title.charCodeAt(title_i) + ";";
  689.             }
  690.             
  691.             description = entity_description;
  692.             title = entity_title;
  693.             body += '  <title type="text/plain" mode="escaped">' + title + '</title>';
  694.             body += '  <issued>' + date + '</issued>';
  695.             body += '  <generator url="http://performancing.com/firefox">' + version + '</generator>';
  696.             body += '  <content type="text/plain" mode="escaped">' + description + '</content>';
  697.             body += '  <draft xmlns="http://purl.org/atom-blog/ns#">' + draft + '</draft> ';
  698.             body += '</entry>';
  699.         }else{
  700.             body += '<draft xmlns="http://purl.org/atom-blog/ns#">' + draft + '</draft> ';
  701.             body += '<title mode="escaped" type="text/plain">' + title + '</title>';
  702.             body += '<issued>' + date + '</issued>';
  703.             if(aAtomID && !url.match(/blogger.com/)) body += '<id>' + aAtomID + '</id>';
  704.             body += '<generator url="http://performancing.com/firefox">' + version + '</generator>'
  705.             body += '<content type="application/xhtml+xml">'
  706.             description = description.replace(/(&\S+)/g, "");
  707.             var containsDIV = description.indexOf("<div xmlns=\"http://www.w3.org/1999/xhtml\">");
  708.             if(containsDIV >= 0){
  709.                 body += description;
  710.             }else{
  711.                 body += '<div xmlns="http://www.w3.org/1999/xhtml">' + description + '</div>';
  712.                 //body += description;
  713.             }
  714.             body += '</content> </entry>';
  715.         }
  716.         
  717.         dump("\n\n********** \nDescription: " + description +"\n\n********** \title: "+ title);
  718.         //dump(body);
  719.         this.doRequest(method,url,body,this.parsePosts, doPublish);
  720.     },
  721.     editPost: function ( postid, title, description, date_created, isDraft, aEditURI, aAtomID) {
  722.         this.doPost( "PUT", postid, title, description, date_created, isDraft, aEditURI, aAtomID, "isEdit");
  723.     },
  724.     newPost: function ( title, description, date_created, isDraft) {
  725.         this.doPost( "POST", null, title, description, date_created, isDraft);
  726.     },
  727.     parsePosts: function( inst) {
  728.         //dump("\n\n NewPost response: " + inst +"\n\n");
  729.         var dom = inst._req.responseXML;
  730.         if(!dom)
  731.         {
  732.             // LiveJournal - everone wants to be different, don't they?
  733.             if(inst._req.responseText.match(/OK/)) {
  734.                 //listener.onResult(1);
  735.                 performancing_xmlcall.processData(1, null, null, "", true);
  736.                 return;
  737.             }
  738.             else {
  739.                 var fault =  {
  740.                     faultString: "Due to Blogger.com's recent API changes,you will need to re-add your Blogger account to PFF\nIf you have problems, please visit the Performancing.com support forums for assistance.\nhttp://performancing.com/forum/firefox"
  741.                 };
  742.                 //fault.faultString += inst._req.responseText;
  743.                 //listener.onFault(fault);
  744.                 var localeString = performancingUI.getLocaleString('atomservererror', []);
  745.                 alert(localeString +"\n"+ fault.faultString);
  746.                 return;
  747.             }
  748.         }
  749.         var entries = dom.getElementsByTagName("entry");
  750.         var rval = new Object();
  751.         try
  752.         {
  753.             var entry_n = entries[0];
  754.             var link_n = null;
  755.             var perm_link_n = null;
  756.             var atomid_n = inst.getNamedChild(entry_n, "id");
  757.             var atomid = "";
  758.             if(atomid_n) atomid = atomid_n.firstChild.nodeValue;
  759.             for(var j=0;j<entry_n.childNodes.length;++j) {
  760.                 if(entry_n.childNodes[j].nodeName=="link") {
  761.                     var tmp = entry_n.childNodes[j];
  762.                     if(tmp.getAttribute("rel").match(/edit/)) {
  763.                         link_n = tmp;
  764.                     }
  765.                     else if(tmp.getAttribute("rel").match(/alternate/)) {
  766.                         perm_link_n = tmp;
  767.                     }
  768.                 }
  769.             }
  770.             var href = link_n.getAttribute("href");
  771.             rval.editURI = href;
  772.             rval.atomid = atomid;
  773.             href.match(/.+\/(.+)/);
  774.             rval.uid = RegExp.$1;;
  775.             //Livejournal hackage
  776.             if(rval.editURI.length>0 && rval.atomid.length==0) {
  777.                 var perm_link = perm_link_n.getAttribute("href");
  778.                 if(perm_link.match(/livejournal/)) {
  779.                     perm_link.match(/.+livejournal.com\/users\/(.+?)\/(.+?)\./);
  780.                     rval.atomid = "urn:lj:livejournal.com:atom1:" + RegExp.$1 + ":" + RegExp.$2;
  781.                     //alert(rval.atomid);
  782.                     //alert(rval.atomid);
  783.                 }
  784.             }
  785.         }
  786.         catch(e)
  787.         {
  788.             var localeString = performancingUI.getLocaleString('proccessingposterror', []);
  789.             alert(localeString);
  790.         }
  791.         performancing_xmlcall.processData(rval, null, 'newpostcall', "", true );
  792.         //performancing_xmlcall.processData(rval, 'historycall', null, true);
  793.     },
  794.     
  795.     handleDelete: function( inst) {
  796.         //listener.onResult(1);
  797.         performancing_xmlcall.processData(1, null, 'deletehistorycall', "", true);
  798.     }
  799. }
  800.  
  801. /*
  802.     Blogger Beta
  803.     -------------------
  804.     GET "http://beta.blogger.com/feeds/214142430004041626/posts/full"
  805.     
  806.     //URL
  807.     theLinks = theGood.getElementsByTagName("link")
  808.     for(i in theLinks){
  809.         if(theLinks[i].getAttribute("rel") == "alternate"){
  810.                  alert(theLinks[i].getAttribute("href") ); 
  811.                  break;
  812.         }
  813.     }
  814.     
  815.     //Title
  816.     theTitles = theGood.getElementsByTagName("title");
  817.     theTitles[0].firstChild.nodeValue;
  818.     
  819.     //ID
  820.     theIDs = theGood.getElementsByTagName("id");
  821.     theIDs[0].firstChild.nodeValue;
  822. */
  823. function perFormancingBloggerAtomAPIObject() {
  824. }
  825. var pffGoogleAuth = "";
  826. var pffGoogleAuthIsLoggedin = false;
  827.  
  828. perFormancingBloggerAtomAPIObject.prototype= {
  829.     titleRegExp: /(?:\<title\stype\=\'\w*\'\>)([\s\S\s]*)(?=\<\/title\>)/,
  830.     getFullIDRegExp: /(?:\<id\>)(\S*)(?=\<\/id\>)/,
  831.     urlRegExp: /(?:\<link\srel\=\'\w*\'\stype\=\'[\w\W]*\'\shref\=\')([\s\S\s]*)(?=\<\/link>)/,
  832.     
  833.     idRegexp: /(?:[\S]*feeds\/)([\d]*)(?=\/posts)/,
  834.     postIDRegexp: /(?:[\S]*posts\/full\/)([\d]*)(?=\")/,
  835.     
  836.     _req: null,
  837.     _url: null,
  838. //    _auth: null,
  839. //    _isLoggedin: false,
  840.  
  841.     ERROR_HTTP:   10,
  842.     ERROR_FAULT:   11,
  843.     ERROR_PARSER:   12,
  844.     
  845.     init2: function( aUrl, aUsername, aPassword) {
  846.         this._url = aUrl;
  847.         this._user = aUsername;
  848.         this._pass = aPassword;
  849.     },
  850.     
  851.     doSetup: function( aUrl, aUsername, aPassword) {
  852.         pffGoogleAuth = "";
  853.         pffGoogleAuthIsLoggedin = false;
  854.     },
  855.     
  856.     doAuth: function(processor) {
  857.         if(!pffGoogleAuthIsLoggedin){
  858.             var theUA = "scribefire-1.4.2";
  859.             var theMsg = "Email="+this._user+"&Passwd="+encodeURIComponent(this._pass)+"&service=blogger&source="+theUA;
  860.             var theCall = new PffXmlHttpReq("https://www.google.com/accounts/ClientLogin", "POST", theMsg, false, null, null);
  861.             var theGood = null; 
  862.             var theBad = null;
  863.             var theProcessor = processor;
  864.             //var theAuth = this._auth;
  865.             var theObject = this;
  866.             theCall.onResult = function( aText, aXML ){ 
  867.                 theGood = aText;
  868.                 theAuth = theGood.match(/(?:Auth\=)(.*)/);
  869.                 pffGoogleAuth = theAuth[1];
  870.                 pffGoogleAuthIsLoggedin = true;
  871.                 theObject.doRequest("GET", theObject._url, null, theProcessor);
  872.             } 
  873.             theCall.onError = function (aStatusMsg, Msg) {
  874.                 var errorType = theCall.request.responseText.split('=')[1].replace(/\s*$/,""); 
  875.                 var errorMessage = '';
  876.                 
  877.                 switch (errorType) {
  878.                     case 'BadAuthentication':
  879.                         errorMessage = performancingUI.getLocaleString('errors.blogger.badauthentication', []);
  880.                         break;
  881.                     case 'NotVerified':
  882.                         errorMessage = performancingUI.getLocaleString('errors.blogger.notverified', []);
  883.                         break;
  884.                     case 'TermsNotAgreed':
  885.                         errorMessage = performancingUI.getLocaleString('errors.blogger.termsnotagreed', []);
  886.                         break;
  887.                     case 'AccountDeleted':
  888.                         errorMessage = performancingUI.getLocaleString('errors.blogger.accountdeleted', []);
  889.                         break;
  890.                     case 'ServiceDisabled':
  891.                         errorMessage = performancingUI.getLocaleString('errors.blogger.servicedisabled', []);
  892.                         break;
  893.                     case 'ServiceUnavailable':
  894.                         errorMessage = performancingUI.getLocaleString('errors.blogger.serviceunavailable', []);
  895.                         break;
  896.                     case 'Unknown':
  897.                     default:
  898.                         errorMessage = performancingUI.getLocaleString('errors.blogger.unknown', []);
  899.                         break;
  900.                 }
  901.                 
  902.                 alert(errorMessage);
  903.             }
  904.             theCall.prepCall(); //Set up The call (open connection, etc.)
  905.             theCall.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  906.             theCall.makeCall();
  907.         }else{
  908.             this.doRequest("GET", this._url, null, processor);
  909.         }
  910.     },
  911.  
  912.     doRequest: function(method, url, body, processor) {
  913.         var inst = this;
  914.         gPFFLastURIPost = url;
  915.         this._req = new XMLHttpRequest();
  916.         this._req.onreadystatechange = function (aEvt) {
  917.             if(inst._req.readyState == 4) {
  918.                 //dump("\nRESPONSE\n" + inst._req.responseText);
  919.                 if(inst._req.status == 200 || inst._req.status == 201 || inst._req.status == 204)
  920.                 {
  921.                     try
  922.                     {
  923.                         processor( inst);
  924.                     }
  925.                     catch(e)
  926.                     {
  927.                         //listener.onError(inst.ERROR_PARSER);
  928.                         var localeString = performancingUI.getLocaleString('atomservererror', []);
  929.                         var localeString2 = performancingUI.getLocaleString('atomerrormessage', [e]);
  930.                         //alert("Processor 2: " + processor);
  931.                         alert(localeString + " #101\n" + localeString2 + "\n" + e + "\nServer Response:" + inst._req.responseText);
  932.                     }
  933.                 }
  934.                 else {
  935.                     var fault =  {
  936.                         faultString: "The blogger.com server faild with the following message:\n\n"
  937.                     };
  938.                     fault.faultString += inst._req.responseText;
  939.                     //listener.onFault(fault);
  940.                     //alert("Error: 1212121");
  941.                     //var localeString = performancingUI.getLocaleString('atomservererror', []);
  942.                     alert(fault.faultString + "\n\nIf you are embedding a video or any rich html,\nplease make sure any unclosed tags are closed\ni.e. <embed> </embed>");
  943.                 }
  944.             }
  945.             //dump("Requested Test 2: this.req.status: " + inst._req.status + "\n");
  946.             //dump("Requested Test 2: this.req.readyState: " + inst._req.readyState + "\n");
  947.         };
  948.         //var aPassword = gPerformancingUtil.usermanagment.getPassword(this.username, this.apiLink);
  949.        // dump("\n\n USERNAME and PASS: " + this._user + " : " + this._pass + "\n\n");
  950.         var rval = this._req.open(method, url, true, this._user, this._pass);
  951.         //dump("\n\n\n\n\nSending: " + method + "\n\n" + url + "\n>>>\n" + body + "\n\n\n\n");
  952.         rval = this._req.setRequestHeader("Authorization", "GoogleLogin auth=" +pffGoogleAuth );
  953.         rval = this._req.setRequestHeader("User-Agent", "Mozilla/5.0 (compatible; ScribeFire; http://www.scribefire.com/)");
  954.         rval = this._req.setRequestHeader("Content-Type", "application/atom+xml");
  955.         rval = this._req.send(body); 
  956.     },
  957.  
  958.     getRecentPosts: function() {
  959.         //var url = this._url; 
  960.         //url.match(/(.+\/)(.+)/);
  961.         //if(RegExp.$2=="post") {
  962.         //    url = RegExp.$1 + "feed";
  963.         //}
  964.         //this.doRequest("GET", this._url,null, this.parseRecentPosts);
  965.         this.doAuth(this.parseRecentPosts);
  966.         return true;
  967.     },
  968.     getUsersBlogs: function() {
  969.         //var url = this._url.match(/(.+)\//);
  970.         //url = RegExp.$1;
  971.         //this.doRequest("GET", this._url, null, this.parseUsersBlogs);
  972.         this.doAuth(this.parseUsersBlogs);
  973.     },
  974.  
  975.     parseUsersBlogs: function( inst) {
  976.         //dump("\n\n parseUsersBlogs ATOM \n\n");
  977.         try {
  978.             var rval = new Array();
  979.             var dom = inst._req.responseXML;
  980.             //gPFFDebugTemp.push(dom);
  981.             //gPFFDebugTemp.push(inst._req.responseText);
  982.             var url = "";
  983.             var id = "";
  984.             var title = "";
  985.             //URL
  986.             var theLinks = dom.getElementsByTagName("link")
  987.             for(i in theLinks){
  988.                 try{
  989.                     if(theLinks[i].getAttribute("rel") == "alternate"){
  990.                              url = (theLinks[i].getAttribute("href") ); 
  991.                              break;
  992.                     }
  993.                 }catch(e){}
  994.             }
  995.             
  996.             //Title
  997.             var theTitles = dom.getElementsByTagName("title");
  998.             title = theTitles[0].firstChild.nodeValue;
  999.             
  1000.             //ID
  1001.             var theIDs = dom.getElementsByTagName("id");
  1002.             try{
  1003.                 id = theIDs[0].firstChild.nodeValue.match(/(?:[\S]*feeds\/)([\d]*)(?=\/posts)/)[1];
  1004.             }catch(e){
  1005.                 id = "";
  1006.             }
  1007.             /*
  1008.             var links = dom.getElementsByTagName("link");
  1009.             for(var i=0;i<links.length;++i)
  1010.             {
  1011.                 var link = links[i];
  1012.                 var title = link.getAttribute("title");
  1013.                 var rel = link.getAttribute("rel");
  1014.                 var href = link.getAttribute("href");
  1015.                 if(rel!="service.post") continue;
  1016.  
  1017.                 href.match(/.+\/(.+)/);
  1018.                 var bid = RegExp.$1;
  1019.  
  1020.                 var obj  =
  1021.                 {
  1022.                     blogName: title,
  1023.                     blogid:  bid,
  1024.                     url:  href
  1025.                 };
  1026.                 rval[rval.length++] = obj;
  1027.             }*/
  1028.             var obj  =
  1029.                 {
  1030.                     blogName: title,
  1031.                     blogid:  id,
  1032.                     url:  url
  1033.                 };
  1034.                 //gPFFDebugTemp.push(obj);
  1035.                 //alert("BlogList:\n" + url + title + id);
  1036.                 rval[rval.length++] = obj;
  1037.             //listener.onResult(rval);
  1038.             performancing_xmlcall.processData(rval, null, 'accountwizard', "", true);
  1039.         }
  1040.         catch(e) {
  1041.             alert("Whoops, you found a Blogger error.\n Please contact the author at 'performancing.com/forum/firefox/'\n and give the following info\n" + e + " " + e.lineNumber);
  1042.             //dump("\n\n Error ParsingBlogs: " + e + "\n\n");
  1043.         }
  1044.     },
  1045.     
  1046.     parseRecentPosts: function( inst) { //Using EX4
  1047.         var rval = new Array();
  1048.         gPFFDebugTemp.push(inst._req.responseText);
  1049.         
  1050.         var re = /(\<\?\xml[0-9A-Za-z\D]*\?\>)/;
  1051.         var newstr = inst._req.responseText.replace(re, "");
  1052.         
  1053.         var re = /(\<feed[0-9A-Za-z\D]*["']>)(?=\<id\>)/;
  1054.         newstr = newstr.replace(re, "<feed>");
  1055.         
  1056.         var re = /(\<\openSearch:[0-9A-Za-z]*\>[\d]+\<\/openSearch:[0-9A-Za-z]*\>)/ig;
  1057.         var newstr = newstr.replace(re, "");
  1058.         
  1059.         var theXML = new XML(newstr);
  1060.         gPFFDebugTemp.push(theXML);
  1061.         
  1062.         for(var i=0; i<theXML.entry.length(); i++){
  1063.             try{
  1064.                 var catArray = [];
  1065.                 //Was 42 and 6
  1066.                 var theContent = theXML.entry[i].content.toString();
  1067.                 
  1068.                 theContent = theContent.replace("<content type=\"xhtml\">\n  ", ""); //Stupid blogger hack
  1069.                 theContent = theContent.replace("\n</content>", ""); //Stupid blogger hack
  1070.                 
  1071.                 var divRegexp = /\<div xmlns\=\'http:\/\/www.w3.org\/1999\/xhtml\'\>|\<div xmlns\=\"http:\/\/www.w3.org\/1999\/xhtml\"\>/;
  1072.                 var divIndex = theContent.search(divRegexp);
  1073.                 
  1074.                 if( divIndex >= 0 && divIndex < 30 ){ //If we have a <div xmlns='http://www.w3.org/1999/xhtml'> at the top
  1075.                     theContent = theContent.substring(42, theContent.length - 6); //Get rid of the outer div
  1076.                 }
  1077.                 var theTitle = theXML.entry[i].title;
  1078.                 var theDate = theXML.entry[i].published;
  1079.                 var thePostURL = theXML.entry[i].id;
  1080.                 var theHREF =  theXML.entry[i].link.(@rel == 'alternate').@href;
  1081.                 var theEditHREF =  theXML.entry[i].link.(@rel == 'edit').@href;
  1082.                 var theCatsObj = theXML.entry[i].category.@term;
  1083.                 
  1084.                 //var atomid = thePostURL.match( /(?:\/)(\d{5,})/ )[1];
  1085.                 //var atomid = thePostURL.match( /(?:\/posts\/)(\d{5,})/ )[1];
  1086.                 var atomid = thePostURL.match( /(?:\/|post-)(\d{5,})(?!\d*\/)/ )[1];
  1087.                 
  1088.                 for(var j=0; j < theCatsObj.length(); j++){
  1089.                     catArray.push( theCatsObj[j].toString() );
  1090.                 }
  1091.                 
  1092.                 
  1093.                 var val = theDate;
  1094.                 //Date.UTC(year, month[, date[, hrs[, min[, sec[, ms]]]]])
  1095.                 var dateutc =  Date.UTC( val.slice(0, 4), val.slice(5, 7) - 1, val.slice(8, 10), val.slice(11, 13), val.slice(14, 16) );
  1096.                 var date =  new Date(dateutc);
  1097.                 
  1098.                 
  1099.                 var obj  =
  1100.                 {
  1101.                     description: theContent,
  1102.                     title: theTitle,
  1103.                     dateCreated: date,
  1104.                     postid:  atomid,
  1105.                     editURI:  theEditHREF,
  1106.                     atomid:  thePostURL,
  1107.                     permaLink: theHREF,
  1108.                     categories: catArray
  1109.                 };
  1110.                 rval[rval.length] = obj;
  1111.                 
  1112.             }catch(e){
  1113.                 //alert("Error Parsing Blogger history\n" + e);
  1114.             }
  1115.         }
  1116.         performancing_xmlcall.processData(rval, null, 'historycall', "", true);
  1117.         
  1118.     },
  1119.  
  1120.     parseRecentPosts_dom: function( inst) {
  1121.         //dump("\n\n parseRecentPosts ATOM \n\n");
  1122.         //gPFFDebugTemp.push(inst._req.responseText);
  1123.         var rval = new Array();
  1124.         var dom = inst._req.responseXML;
  1125.         var entries = dom.getElementsByTagName("entry");
  1126.         for(var i=0;i<entries.length;++i)
  1127.         {
  1128.             try
  1129.             {
  1130.                 var entry_n = entries[i];
  1131.                 var content_n = inst.getNamedChild(entry_n, "content");
  1132.                 var title_n = inst.getNamedChild(entry_n, "title");
  1133.                 var date_n = inst.getNamedChild(entry_n, "updated");
  1134.                 //var author_n = inst.getNamedChild(entry_n, "author");
  1135.                 var posturl_n = inst.getNamedChild(entry_n, "id");
  1136.                 var atomid = "";
  1137.                 var link_n = "";
  1138.                 var postlink = "";
  1139.                 
  1140.                 var content = content_n.firstChild.nodeValue;
  1141.                 var title = title_n.firstChild.nodeValue;
  1142.                 var date = date_n.firstChild.nodeValue;
  1143.                 var posturl = posturl_n.firstChild.nodeValue;
  1144.                 //atomid = posturl_n.match(postIDRegexp)[1];
  1145.                 if(content == null){
  1146.                     try{
  1147.                         content = content_n.firstChild.firstChild.nodeValue;
  1148.                     }catch(e){
  1149.                         
  1150.                     }
  1151.                 }
  1152.                 
  1153.                 if(content == null){
  1154.                     content = "";
  1155.                 }
  1156.                 var theCats = [];//Define the categories (labels)
  1157.                 //if(atomid_n) atomid = atomid_n.firstChild.nodeValue;
  1158.                 for(var j=0;j<entry_n.childNodes.length;++j) {
  1159.                     if(entry_n.childNodes[j].nodeName=="link") {
  1160.                         var tmp = entry_n.childNodes[j];
  1161.                         if(tmp.getAttribute("rel").match(/edit/)) {
  1162.                             link_n = tmp;
  1163.                         }
  1164.                         if(tmp.getAttribute("rel").match(/alternate/)) {
  1165.                             postlink = tmp;
  1166.                         }
  1167.                     }else if(entry_n.childNodes[j].nodeName=="category") {
  1168.                         var tmp = entry_n.childNodes[j];
  1169.                         var term = tmp.getAttribute("term");
  1170.                         theCats.push(term);
  1171.                     }
  1172.                 }
  1173.                 
  1174.                 var href = link_n.getAttribute("href");
  1175.                 atomid = href.match(/.+\/(.+)/)[1];
  1176.                 
  1177.                 var thePostlink = postlink.getAttribute("href");
  1178.                 
  1179.                 var val = date;
  1180.                 var dateutc =  Date.UTC( val.slice(0, 4), val.slice(5, 7), val.slice(8, 10), val.slice(11, 13), val.slice(14, 16) );
  1181.                 var date =  new Date(dateutc);
  1182.  
  1183.                 var xs = new XMLSerializer();
  1184.  
  1185.                 /*
  1186.                 var data = "";
  1187.                 if(content_n) {
  1188.                     for(var j=0;j<content_n.childNodes.length;++j) {
  1189.                         data += xs.serializeToString(content_n.childNodes.item(j));
  1190.                     }
  1191.                 }
  1192.                 data = data.replace(/</g,"<");
  1193.                 data = data.replace(/>/g,">");
  1194.                 data = data.replace(/"/g,"\"");
  1195.                 data = data.replace(/&/g,"&"); */
  1196.                 var obj  =
  1197.                 {
  1198.                     description: content,
  1199.                     title: title,
  1200.                     dateCreated: date,
  1201.                     postid:  atomid,
  1202.                     editURI:  href,
  1203.                     atomid:  posturl,
  1204.                     permaLink: thePostlink,
  1205.                     categories: theCats
  1206.                 };
  1207.                 rval[rval.length] = obj;
  1208.             }
  1209.             catch(e)
  1210.             {
  1211.                 //alert(e);
  1212.                 //dump("\n\n parseRecentPosts ATOM ERROR:" + e + "\n\n");
  1213.             }
  1214.         }
  1215.         //listener.onResult(rval);
  1216.         //dump("\n\n parseRecentPosts ATOM Finished \n\n");
  1217.         //gLastPostID = postid;
  1218.         performancing_xmlcall.processData(rval, null, 'historycall', "", true);
  1219.     },
  1220.     getNamedChild: function(node, name) {
  1221.         for(var i=0;i<node.childNodes.length;++i) {
  1222.             if(node.childNodes[i].nodeName==name) return node.childNodes[i];
  1223.         }
  1224.         return null;
  1225.     },
  1226.     deletePost: function ( postid, aEditURI) {
  1227.         var url = this._url;
  1228.         if(postid) url += "/" + postid;
  1229.         if(aEditURI) url = aEditURI;
  1230.         this.doRequest("DELETE", url,null, this.handleDelete);
  1231.     },
  1232.     
  1233.     doPost: function ( method, postid, title, description, date_created, doPublish, aEditURI, aAtomID, isEdit) {
  1234.  
  1235.         var url = this._url;
  1236.         if(postid) url += "/" + postid;
  1237.  
  1238.         //if(aEditURI) url += "/" + aEditURI;
  1239.  
  1240.         //var date = bfXMLRPC.iso8601Format(date_created);
  1241.         var date = "";
  1242.         try{
  1243.             date = bfXMLRPC.iso8601Format(date_created);
  1244.         }catch(e){
  1245.             //foo
  1246.         }
  1247.         var body = "";
  1248.         var version = "ScribeFire 1.4.2";
  1249.         var theBlogCharType = gPerformancingUtil.getCharType();
  1250.         body += '<?xml version="1.0" encoding="UTF-8" ?>';
  1251.         body += '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#">';
  1252.  
  1253.         var draft = false;
  1254.         if(doPublish == false || doPublish == 'bool0') draft = true;
  1255.         
  1256.         description = description.replace(/ /g, ' ');
  1257.         description = description.replace(/&/g, '&');
  1258.         description = description.replace(/&/g, '&');
  1259.         title = title.replace(/&/g, '&');
  1260.         title = title.replace(/&/g, '&');
  1261.         
  1262.        // alert("Is Draft? " + draft + " doPublish: " + doPublish);
  1263.         
  1264.         var useEntities = true;
  1265.         try{
  1266.             useEntities = gPerformancingUtil.prefs.getBoolPref('publish.usehtmlentities')
  1267.         }catch(e){
  1268.             useEntities = false;
  1269.         }
  1270.         
  1271.         //Use HTML Entities, thanks Theo
  1272.         useEntities = false;
  1273.         
  1274.         if(useEntities){
  1275.             var entity_description = "";
  1276.             for (var desc_i=0; desc_i < description.length; desc_i++){
  1277.                 entity_description += "&#" + description.charCodeAt(desc_i) + ";";
  1278.             }
  1279.         
  1280.             var entity_title = "";
  1281.             for (var title_i=0; title_i < title.length; title_i++){
  1282.                 entity_title += "&#" + title.charCodeAt(title_i) + ";";
  1283.             }
  1284.             
  1285.             description = entity_description;
  1286.             title = entity_title;
  1287.             /*
  1288.             <entry xmlns='http://www.w3.org/2005/Atom'>
  1289.               <title type='text'>Marriage!</title>
  1290.               <content type='xhtml'>
  1291.                 <div xmlns="http://www.w3.org/1999/xhtml">
  1292.                   <p>Mr. Darcy has <em>proposed marriage</em> to me!</p>
  1293.                   <p>He is the last man on earth I would ever desire to marry.</p>
  1294.                   <p>Whatever shall I do?</p>
  1295.                 </div>
  1296.               </content>
  1297.               <author>
  1298.                 <name>Elizabeth Bennet</name>
  1299.                 <email>liz@gmail.com</email>
  1300.               </author>
  1301.             </entry>
  1302.             */
  1303.             body += '  <title type="text/plain" mode="escaped">' + title + '</title>';
  1304.             body += '  <issued>' + date + '</issued>';
  1305.             body += '  <generator url="http://performancing.com/firefox">' + version + '</generator>';
  1306.             body += '  <content type="text/plain" mode="escaped">' + description + '</content>';
  1307.             //body += '  <draft xmlns="http://www.w3.org/2005/Atom">' + draft + '</draft> ';
  1308.             body += '</entry>';
  1309.         }else{
  1310.             //Set the Labels (categories)
  1311.             var getLabelArray = gPerformancingUtil.getArrOfCatChecked('blog-sidebar-listing-categories', false);
  1312.             if( getLabelArray != "" && getLabelArray.length > 0 ){
  1313.                 for(var i=0; i < getLabelArray.length; i++){
  1314.                     body += '<category scheme="http://www.blogger.com/atom/ns#" term="'+getLabelArray[i].replace(/&/g,'&')+'"/>';
  1315.                 }
  1316.             }
  1317.             
  1318.             body += '<title mode="escaped" type="text">' + title + '</title>';
  1319.             body += '<issued>' + date + '</issued>';
  1320.             body += '<content type="xhtml">'
  1321.            // description = description.replace(/(&\S+)/g, "");
  1322.             var containsDIV = description.indexOf("<div xmlns=\"http://www.w3.org/1999/xhtml\">");
  1323.             if(containsDIV >= 0){
  1324.                 body += description;
  1325.             }else{
  1326.                 body += '<div xmlns="http://www.w3.org/1999/xhtml">' + description + '</div>';
  1327.             }
  1328.             body += '</content>';
  1329.             
  1330.             if(draft){
  1331.                 body += '<app:control>';
  1332.                 body += '  <app:draft>yes</app:draft>';
  1333.                 body += '</app:control>';
  1334.             }else{
  1335.                // body += '<app:control>';
  1336.                 //body += '  <app:draft>no</app:draft>';
  1337.                 //body += '</app:control>';
  1338.             }
  1339.             body += ' </entry>';
  1340.         }
  1341.         dump("\n\n********** \nDescription: " + description +"\n\n********** \title: "+ title);
  1342.         
  1343.         this.doRequest(method,url,body,this.parsePosts, doPublish);
  1344.     },
  1345.     editPost: function ( postid, title, description, date_created, isDraft, aEditURI, aAtomID) {
  1346.         this.doPost( "PUT", postid, title, description, date_created, isDraft, aEditURI, aAtomID, "isEdit");
  1347.     },
  1348.     newPost: function ( title, description, date_created, isDraft) {
  1349.         this.doPost( "POST", null, title, description, date_created, isDraft);
  1350.     },
  1351.     parsePosts: function( inst) {
  1352.         //dump("\n\n NewPost response: " + inst +"\n\n");
  1353.         //gPFFDebugTemp.push(inst._req.responseXML);
  1354.         //gPFFDebugTemp.push(inst._req.responseText);
  1355.         var dom = inst._req.responseXML;
  1356.         //alert("The Post!!:\n"+ inst._req.responseText);
  1357.         if(!dom)
  1358.         {
  1359.             // LiveJournal - everone wants to be different, don't they?
  1360.             if(inst._req.responseText.match(/OK/)) {
  1361.                 //listener.onResult(1);
  1362.                 performancing_xmlcall.processData(1, null, null, "", true);
  1363.                 return;
  1364.             }
  1365.             else {
  1366.                 var fault =  {
  1367.                     faultString: "There was an error posting to your blog.\nPlease make sure you are posting valid HTML and try again."
  1368.                 };
  1369.                 fault.faultString += inst._req.responseText;
  1370.                 //listener.onFault(fault);
  1371.                 var localeString = performancingUI.getLocaleString('atomservererror', []);
  1372.                 //alert("Error: 323232" );
  1373.                 alert(localeString +" #301\nServer Response: "+ inst._req.responseText);
  1374.                 return;
  1375.             }
  1376.         }
  1377.         var entries = dom.getElementsByTagName("entry");
  1378.         var rval = new Object();
  1379.         try
  1380.         {
  1381.             var entry_n = entries[0];
  1382.             var link_n = null;
  1383.             var perm_link_n = null;
  1384.             var atomid_n = inst.getNamedChild(entry_n, "id");
  1385.             var atomid = "";
  1386.             if(atomid_n) atomid = atomid_n.firstChild.nodeValue;
  1387.             for(var j=0;j<entry_n.childNodes.length;++j) {
  1388.                 if(entry_n.childNodes[j].nodeName=="link") {
  1389.                     var tmp = entry_n.childNodes[j];
  1390.                     if(tmp.getAttribute("rel").match(/edit/)) {
  1391.                         link_n = tmp;
  1392.                     }
  1393.                     else if(tmp.getAttribute("rel").match(/self/)) {
  1394.                         perm_link_n = tmp;
  1395.                     }
  1396.                 }
  1397.             }
  1398.             var href = link_n.getAttribute("href");
  1399.             rval.editURI = href;
  1400.             rval.atomid = atomid;
  1401.             href.match(/.+\/(.+)/);
  1402.             rval.uid = RegExp.$1;;
  1403.             //Livejournal hackage
  1404.             if(rval.editURI.length>0 && rval.atomid.length==0) {
  1405.                 var perm_link = perm_link_n.getAttribute("href");
  1406.                 if(perm_link.match(/livejournal/)) {
  1407.                     perm_link.match(/.+livejournal.com\/users\/(.+?)\/(.+?)\./);
  1408.                     rval.atomid = "urn:lj:livejournal.com:atom1:" + RegExp.$1 + ":" + RegExp.$2;
  1409.                     //alert(rval.atomid);
  1410.                     //alert(rval.atomid);
  1411.                 }
  1412.             }
  1413.         }
  1414.         catch(e)
  1415.         {
  1416.             var localeString = performancingUI.getLocaleString('proccessingposterror', []);
  1417.             alert(localeString);
  1418.         }
  1419.         performancing_xmlcall.processData(rval, null, 'newpostcall', "", true );
  1420.         //performancing_xmlcall.processData(rval, 'historycall', null, true);
  1421.     },
  1422.     
  1423.     handleDelete: function( inst) {
  1424.         //listener.onResult(1);
  1425.         performancing_xmlcall.processData(1, null, 'deletehistorycall', "", true);
  1426.     }
  1427. }
  1428. //perFormancingBloggerAtomAPIObject.prototype = new perFormancingBlogAPI();
  1429.  
  1430.